<?php

namespace app\admin\model;

use think\Model;

class Ad extends Model
{
    // 表名
    protected $name = 'ad';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    
    // 追加属性
    protected $append = [
        'ad_position_text',
        'type_text',
        'ad_type_text',
    ];
    

    
    public function getAdPositionList()
    {
        return ['1' => __('车主端'),'2' => __('扫码人端')];
    }     

    public function getTypeList()
    {
        return ['1' => __('二维码编号'),'2' => __('激活编号')];
    }   
    
    public function getAdTypeList()
    {
        return ['1' => __('详情页'),'2' => __('H5')];
    }   


    public function getAdPositionTextAttr($value, $data)
    {        
        $value = $value ? $value : $data['ad_position'];
        $list = $this->getAdPositionList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getTypeTextAttr($value, $data)
    {        
        $value = $value ? $value : $data['type'];
        $list = $this->getTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }
    
    public function getAdTypeTextAttr($value, $data)
    {        
        $value = $value ? $value : $data['ad_type'];
        $list = $this->getAdTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }
    




}
